package com.foodapp.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.foodapp.back.entity.OrderItem;
import com.foodapp.back.mapper.OrderItemMapper;
import com.foodapp.back.service.OrderItemService;
import com.foodapp.back.vo.OrderItemVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单项服务实现类
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {

    @Override
    public List<OrderItemVO> getOrderItemsByOrderId(Long orderId) {
        // 查询订单项
        LambdaQueryWrapper<OrderItem> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderItem::getOrderId, orderId);
        List<OrderItem> orderItems = list(wrapper);
        
        // 转换为VO
        return orderItems.stream().map(item -> {
            OrderItemVO vo = new OrderItemVO();
            BeanUtils.copyProperties(item, vo);
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public boolean saveBatch(List<OrderItem> orderItems) {
        return super.saveBatch(orderItems);
    }
}
